package com.vijos;

//ISBN号码
public class P2_3_1484 {

    public static int test(String input) {
        char[] chars = input.toCharArray();
        int count = 1;
        int sum = 0;
        int seq = 0;
        for (int i = 0; i < chars.length; i++) {
            int num = chars[i] - 48;
            if (num >= 0 && count <= 9) {
                sum += num * count++;
            }
            if (i == chars.length - 1) {
                seq = num;
            }
        }
        int mod = sum % 11;
        if (mod == seq) {
            // 正确
            return -1;
        } else {
            return mod;
        }
    }

    public static void main(String[] args) {
        // -1代表正确，否则返回正数的序列号
        System.out.println(test("0-670-82162-4"));
        System.out.println(test("0-670-82162-5"));
    }
}
